package com.server.llh.llhserverwork.activity.food;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.lelaohui.net.BaseLeLaohuiAcitivity;
import com.lelaohui.net.netmanager.INetRequestManager;
import com.lelaohui.net.netmanager.NetRequestManager;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.adapter.base.ListFragmentPagerAdapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ZTF on 2017-05-27.
 */

public class FoodOrderAllFragment extends BaseLeLaohuiAcitivity implements TabLayout.OnTabSelectedListener{
    @BindView(R.id.left_btn)
    ImageButton leftBtn;
    @BindView(R.id.titlebar_text)
    TextView titlebarText;
    @BindView(R.id.right_btn)
    Button rightBtn;
    ViewPager mViewPager;
    @BindView(R.id.tab_layou)
    TabLayout tabLayout;

    private ArrayList<Fragment> list = new ArrayList<Fragment>();
    ListFragmentPagerAdapter mPagerAdapter;
    private final int FIRST_FRAGMENT = 0;
    private final int SECOND_FRAGMENT = 1;
    private String[] titles=new String[]{"近一个月","全部订单" };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        titlebarText.setText("我的餐饮订单");
        //设置TabLayout标签的显示方式
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
//        tabLayout.setupWithViewPager(mViewPager);
        //循环注入标签
        for (String tab:titles){
            tabLayout.addTab(tabLayout.newTab().setText(tab));
        }
        //设置TabLayout点击事件
        tabLayout.setOnTabSelectedListener(this);
        mViewPager = (ViewPager) findViewById(R.id.id_vp_viewpager);
        mViewPager.setOffscreenPageLimit(1);
        list.add(LlhFoodOrderAllFragment.newInstance(FIRST_FRAGMENT));
        list.add(LlhFoodOrderAllFragment.newInstance(SECOND_FRAGMENT));
        mPagerAdapter = new ListFragmentPagerAdapter(getSupportFragmentManager(), list, 2);
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setOnPageChangeListener(onPageChangeListener);

    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
    private ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int arg0) {

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    };


    @OnClick(R.id.left_btn)
    public void onViewClicked() {
        onBackPressed();
    }

    @Override
    public void showProgress() {


    }

    @Override
    public void hideProgress() {

    }

    @Override
    protected int getlayout() {
        return R.layout.llh_orderall_fragment;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void doBasess() {

    }

    @Override
    protected INetRequestManager getRequestManager() {
        return NetRequestManager.getInstance();
    }


}
